package com.example.zhu95.mytimber.listener;

import android.view.MotionEvent;
import android.view.View;

import jp.co.recruit_lifestyle.android.widget.PlayPauseButton;

/**
 * @author zhu95
 * @date 2018/3/16 17:53
 */
public class PlayPauseBtnOnTouchListener implements View.OnTouchListener {

    PlayPauseButton.OnControlStatusChangeListener onControlStatusChangeListener;

    public PlayPauseBtnOnTouchListener(PlayPauseButton.OnControlStatusChangeListener onControlStatusChangeListener) {
        this.onControlStatusChangeListener = onControlStatusChangeListener;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (v instanceof PlayPauseButton) {
            PlayPauseButton btn = (PlayPauseButton) v;
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                btn.setPlayed(!btn.isPlayed());
                btn.startAnimation();
                if (onControlStatusChangeListener != null) {
                    onControlStatusChangeListener.onStatusChange(v, btn.isPlayed());
                }
                return true;
            }
        }
        return false;
    }
}
